package com.im323.ip.impl;

import com.im323.common.util.HttpClientUtils;
import com.im323.common.util.IpModel;
import com.im323.common.util.IpUtil;
import com.im323.ip.IpConverter;

public class IpMyIpConvert extends IpConverter {

	@Override
	public IpModel parse() {
		long sta = System.currentTimeMillis();
		String doGet = HttpClientUtils.doGet(IpUtil.URL_MYIP);
		IpModel ipModel = null;
		if (doGet != null) {
			int startIndex = doGet.indexOf("我的 IP 是");
			startIndex = doGet.indexOf(">", startIndex) + 1;
			int endIndex = doGet.indexOf("<", startIndex);

			String ip = doGet.substring(startIndex, endIndex);

			ipModel = new IpModel();
			ipModel.setIpAddress(ip);
			ipModel.setDelay(System.currentTimeMillis() - sta);
			ipModel.setUrl(IpUtil.URL_MYIP);
		}
		return ipModel;
	}

}
